package com.example.day1210_section_information.slice;

import com.example.day1210_section_information.ResourceTable;
import com.example.day1210_section_information.fraction.NewsListFraction;
import com.example.day1210_section_information.fraction.VideoFration;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionManager;
import ohos.aafwk.ability.fraction.FractionScheduler;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        initCompent();
    }

    /**
     * 初始化组件
     */
    private void initCompent() {
        // 主页
        DirectionalLayout pageDir = findComponentById(ResourceTable.Id_main_page_dir);
        pageDir.setClickedListener(component -> jumpFrame(new NewsListFraction()));
        // 视频
        DirectionalLayout videoDir = findComponentById(ResourceTable.Id_main_video_dir);
        videoDir.setClickedListener(component -> jumpFrame(new VideoFration()));
        // 圈子
        DirectionalLayout circleDir = findComponentById(ResourceTable.Id_main_quanzi_dir);
        circleDir.setClickedListener(component -> jumpFrame(new VideoFration()));
        // 我的
        DirectionalLayout mineDir = findComponentById(ResourceTable.Id_main_mine_dir);
        mineDir.setClickedListener(component -> jumpFrame(new VideoFration()));


        DirectionalLayout comFrame = findComponentById(ResourceTable.Id_main_frame);

        FractionAbility ability = (FractionAbility) getAbility();
        // 获取片段管理器
        FractionManager fractionManager = ability.getFractionManager();
        // 开启一个片段调度器
        FractionScheduler fractionScheduler = fractionManager.startFractionScheduler();
        // 将布局和fraction 关联
        fractionScheduler.add(ResourceTable.Id_main_frame, new NewsListFraction());
// 提交保存
        fractionScheduler.submit();
    }

    // 点击跳转页面
    private void jumpFrame(Fraction fraction) {


    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
